package cn.linkai.redis;

import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class JedispoolTest {

    private final static String REDIS_ADDRESS="119.29.8.201";
    @Test
    public void testPool(){
        JedisPoolConfig config=new JedisPoolConfig();
        config.setMaxTotal(100);//设置最大连接数
        config.setMaxIdle(10);//设置最大空闲数

        JedisPool pool=new JedisPool(config,REDIS_ADDRESS,6379);
        Jedis jedis=null;
        try {
            jedis=pool.getResource();
            jedis.auth("helloredis");
            jedis.set("name","link");
            String name = jedis.get("name");
            System.out.println(name);
        }catch (Exception ex){
            ex.printStackTrace();
        }finally {
            if(jedis!=null){
                jedis.close();
            }
        }
    }
}
